//
//  RetweetedCell.swift
//  Sina
//
//  Created by 管观荣 on 15/9/28.
//  Copyright © 2015年 CHer. All rights reserved.
//

import UIKit

class RetweetedCell: HomeCell {

    override var viewModel : HomeViewModel?{
        
        didSet{
            
            label.text = viewModel?.retweetedText
            // 修改配图视图高度
            pictureView.snp_updateConstraints { (make) -> Void in
                // 使用计算完成的大小，设置约束数值！
                make.width.equalTo(pictureView.bounds.width)
                make.height.equalTo(pictureView.bounds.height)
                
                let offset = (pictureView.bounds.height == 0) ? 0 : WBHomeCellMargin
               make.top.equalTo(label.snp_bottom).offset(offset)
           }
        }
    }
    override func setupUI() {
        super.setupUI()
        //插入子控件
        contentView .insertSubview(backBtn, aboveSubview: pictureView)
        contentView.insertSubview(label, belowSubview: backBtn)
        
        // 自动布局
        backBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(WBHomeCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
        }
        
        label.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backBtn.snp_top).offset(WBHomeCellMargin)
            make.left.equalTo(backBtn.snp_left).offset(WBHomeCellMargin)
        }
        
        // 设置配图视图的约束！
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(label.snp_bottom).offset(WBHomeCellMargin)
            make.left.equalTo(label.snp_left)
            make.width.equalTo(290)
            make.height.equalTo(290)
        }

        
    }
    private lazy var label : UILabel = UILabel(title:"我是被转发的微博,我不是我不是被转发的微博", color: UIColor.lightGrayColor(), fontSize: 14, layoutWidth: UIScreen.mainScreen().bounds.width - 2 * WBHomeCellMargin)
    
    private lazy var backBtn : UIButton = {
        let backBtn = UIButton()
        backBtn.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        
        return backBtn
    }()

}
